package com.bite.demo;

import com.bite.demo.component.UserComponent;
import com.bite.demo.config.UserConfig;
import com.bite.demo.controller.UserController;
import com.bite.demo.model.UserInfo;
import com.bite.demo.repository.UserRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;


@SpringBootApplication
public class SpringIocApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);
		UserController bean = context.getBean(UserController.class);
		System.out.println(bean);
		bean.sayHi();

//		UserService userService = context.getBean(UserService.class);//根据类型获取Bean
//		System.out.println(userService);
//		//根据名称获取Bean
//		UserService userService2 = (UserService) context.getBean("userService");
//		System.out.println(userService2);
//		//根据类型和名称获取
//		UserService userService3 = context.getBean("userService", UserService.class);
//		System.out.println(userService3);
//		userService.sayHi();
//
//		UserRepository userRepository = context.getBean(UserRepository.class);
//		userRepository.sayHi();
//
//		UserComponent userComponent = context.getBean(UserComponent.class);
//		userComponent.sayHi();
//
//		UserConfig userConfig = context.getBean(UserConfig.class);
//		userConfig.sayHi();
//
//		UserConfig userConfig = (UserConfig) context.getBean("config");
//		userConfig.sayHi();
//
//		UserInfo bean = context.getBean("u1", UserInfo.class);
//		System.out.println(bean);
//		UserInfo bean2 = context.getBean("u2", UserInfo.class);
//		System.out.println(bean2);
	}

}
